package com.example.thirdhomework

import android.annotation.SuppressLint
import android.content.ActivityNotFoundException
import android.content.Intent
import android.graphics.Bitmap
import android.os.Bundle
import android.provider.MediaStore
import android.util.Log
import android.widget.ImageView
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity


const val FIRST_MSG = "Hello from Main"
const val SECOND_MSG = "Hello from Second"

class MainActivity : AppCompatActivity() {
    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        val button1 = findViewById<android.widget.Button>(R.id.button1)
        val edittext =findViewById<android.widget.EditText>(R.id.editText)
        button1.setOnClickListener {
            val intent = Intent(this, SecondActivity::class.java)
            intent.putExtra(FIRST_MSG, edittext.text.toString())
            startActivity( intent)
        }


        val button2 =  findViewById<android.widget.Button>(R.id.button2)
        button2.setOnClickListener {
            val intent = Intent(this, ThirdActivity::class.java)
            startActivityForResult(intent, 0)
        }


        val button3 = findViewById<android.widget.Button>(R.id.button3)
        button3.setOnClickListener {
            val intent = Intent(this, FourthActivity::class.java)
            startActivity(intent)
        }

        val button4 = findViewById<android.widget.Button>(R.id.button4)
        button4.setOnClickListener{
            val intent = Intent(this, FifthActivity::class.java)
            startActivity(intent)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 0) {
            if ( resultCode== 1) {
                val textView = findViewById<TextView>(R.id.textView)
                textView.text = data?.getStringExtra(SECOND_MSG)
            }
        }
    }
}